/**
 * 
 */
package br.srv.full.virtual.postalServices.engine;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateful;

import br.srv.full.entities.address.AddressType;
import br.srv.full.virtual.postalServices.base.PostalServices;
import br.srv.full.virtual.postalServices.base.PostalServicesBeansManagerLocal;
import br.srv.full.virtual.postalServices.base.PostalServicesRemote;

/**
 * @author Carlos Delfino
 * 
 */
@Stateful
public class PostalServiceEJB3 implements PostalServices, PostalServicesRemote, Serializable {

	@EJB
	private PostalServicesBeansManagerLocal beansManager;
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see br.srv.full.virtual.postalServices.base.PostalServices#getAddressTypes()
	 */
	@Override
	public List<AddressType> getAddressTypes() {
		Object l_find = beansManager.find(AddressType.class);
		ArrayList<AddressType> l_types = null;
		if (l_find instanceof Collection) {
			Collection l_tmptypes = (Collection) l_find;
			l_types = new ArrayList<AddressType>(l_tmptypes.size());
			for (Object l_object : l_tmptypes) {
				l_types.add((AddressType) l_object);
			}
			
		}else if (l_find instanceof AddressType) {
			l_types = new ArrayList<AddressType>();
			l_types.add((AddressType) l_find);
		}
		return l_types;
	}

}
